package algo;

import java.util.Iterator;

import dm.bsi.Container;
import dm.bsi.Node;

public class LoadBalance {
	/**
	 * 获取最悠闲的工作节点
	 * @param nodes
	 * @return
	 */
	public static Node getIdlestNode(Node[] nodes)
	{
		if(nodes.length == 1)
		{
			return nodes[0];
		}
		
		int max = Integer.MAX_VALUE;
		int bestIndex = 0;
		for(int i = 0; i < nodes.length; ++i)
		{
			if(nodes[i].isReady() && nodes[i].getContainers().size() < max)
			{
				max = nodes[i].getContainers().size();
				bestIndex = i;
			}
		}
		return nodes[bestIndex];
	}
}
